﻿namespace EyeOpen.Security.Data.Nhibernate
{   
    using System;
    using System.Collections.Generic;
    using EyeOpen.Data.Nhibernate;
    using EyeOpen.Domain;
    using EyeOpen.Queries;
    using NHibernate;

    public class NhibernateSecurityDataContext : NhibernateDataContext, ISecurityDataContext
    {
        public NhibernateSecurityDataContext(ISession session)
            : base(session)
        {
        }

        public void Add(User user) 
        {
            Save(user);
        }

        public void Add(Credential credential)
        {
            Save(credential);
        }

        public void Add(Meta meta)
        {
            Save(meta);
        }

        public override IEnumerable<TResult> GetByQuery<TSource, TResult>(IQuery<TSource, TResult> query)
        {
            if (query == null)
            {
                throw new ArgumentNullException("query");
            }

            return
                new QueryTranslator()
                    .ExecuteQuery(Session, query);
        }
    }
} 